package com.design.patterns.principle.dependenceinversionprinciple.observe;

/**
 *
 * 遵守依赖倒转原则，高层类不依赖底层类，依赖抽象而不依赖具体。即面向接口编程
 *
 * @author Wangzhiwen
 */
public class ObserveDependenceInversionPrinciple {

    public static void main(String[] args) {

        Person person = new Person();
        person.receive(new Email());
        person.receive(new QQ());

    }

}

/**
 * 遵守依赖倒转原则
 * Person类中的接收信息对象不在是具体的，而是依赖其抽象消息接口。
 * 需求发生变更时，只需要扩展消息接口的实现类。而在Person类中不需要增加方法，也不需要改动。
 */
class Person{

    public void receive(Receive receive){
        receive.info();
    }

}

interface Receive{
    void info();
}

class Email implements Receive{

    @Override
    public void info() {
        System.out.println("Email--消息");
    }
}

class QQ implements Receive{

    @Override
    public void info() {
        System.out.println("QQ--消息");
    }
}